package com.validant.enigma3.common;

import java.io.IOException;

import org.testng.ITestContext;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;

import com.validant.enigma3.controls.ExtWebDriver;

public class TestBase {
	
	protected ExtWebDriver driver;
	protected UIMap uimap;
	
	@Parameters({Constants.PARAM_LOCAL_URL})
	@BeforeSuite(alwaysRun = true)
	public void beforeSuite(ITestContext context, String localurl) throws IOException {
		// get all UI controls
		uimap = new UIMap(Configuration.getUIMapFile(), Utils.getClassName(this));
		
		// init web driver
		driver = new ExtWebDriver(localurl);
		
		// add driver into context. This is used for ScreenshotHTMLReporter
		context.setAttribute(Constants.CON_DRIVER_ATTR, driver.getWebDriver());
	}
	
	@AfterSuite
	public void afterSuite() {
		// do something
	}
	
	@BeforeTest
	public void beforeTest()
    {
		// launch the web application under test
    	driver.launch();
    	
    	// wait for the page loaded successfully
    	driver.waitForPageLoaded();
    }  
    
   @AfterTest
   public void afterTest()
   {
		// close browser
		driver.quit();   
   }
   
}
